<?php

class ImageWebsiteController extends Controller
{
	public function filters()
	{
		return array(
			'rights', // perform access control for CRUD operations
		);
	}
	public function allowedActions()
	{
		//return 'error';
	}
	
	public function actionIndex()
	{
		$model = new ImageWebsite('search');
		$model->unsetAttributes();  // clear any default values
		
		if(isset($_GET['ImageWebsite']))
			$model->attributes=$_GET['ImageWebsite'];

		$this->render('index',array(
			'model'=>$model,
		));
	}
	

	public function loadModel($id)
	{
		$model=ImageWebsite::model()->findByPk($id);
		if($model===null)
			throw new CHttpException(404,'The requested page does not exist.');
		return $model;
	}
	
	public function actionDelete($id)
	{
		$this->loadModel($id)->delete();

		// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
		if(!isset($_GET['ajax']))
			$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
	}
	
	// function delete rows
	public function actionDeleteAll($id){
		$arrIdNew = explode(",",$id);
		for($i=0; $i<count($arrIdNew); $i++){
			$model = ImageWebsite::model()->findByPk($arrIdNew[$i]);
			$model1 = CategoriesWebsite::model()->findByPk($model->id_categoiresWebsite);
			$model1->numberWebsite = $model1->numberWebsite-1;
			$model1->save();
			$this->loadModel($arrIdNew[$i])->delete();
		}
		if(!isset($_GET['ajax']))
			$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
	}
}